<?php
/**
 * Created by PhpStorm.
 * User: zhengkunming
 * Date: 2018/12/27
 * Time: 11:37 AM
 */

require_once 'mysql_config.php';

$openid = isset($_POST['openid']) ? $_POST['openid'] : '';
$full_name = isset($_POST['full_name']) ? $_POST['full_name'] : '';
$mobile = isset($_POST['mobile']) ? $_POST['mobile'] : '';
$shop = isset($_POST['shop']) ? $_POST['shop'] : '';

if ('' === $openid) {
    $data = array(
        'code' => -1,
        'data' => array(),
        'msg' => 'require openid'
    );
    rtJson($data);
    return;
}

if ('' === $full_name) {
    $data = array(
        'code' => -1,
        'data' => array(),
        'msg' => 'require full name'
    );
    rtJson($data);
    return;
}

if ('' === $mobile) {
    $data = array(
        'code' => -1,
        'data' => array(),
        'msg' => 'require mobile'
    );
    rtJson($data);
    return;
}

if ('' === $shop) {
    $data = array(
        'code' => -1,
        'data' => array(),
        'msg' => 'require shop'
    );
    rtJson($data);
    return;
}

$query = 'UPDATE users SET full_name = "' . $full_name . '", mobile = "' . $mobile . '", shop = "' . $shop . '" WHERE openid = "' . $openid . '"';


$query_res = mysqli_query($link, $query);

$affected_rows = mysqli_affected_rows($link);


if (TRUE === $query_res && 0 < $affected_rows) {
    $data = array(
        'code' => 0,
        'data' => array(),
        'msg' => 'update success'
    );
    rtJson($data);
    return;
} else if (0 === $affected_rows || FALSE === $query_res) {
    $data = array(
        'code' => -2,
        'data' => array(),
        'msg' => 'update fail'
    );
    rtJson($data);
    return;
}